/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.netbeans.lib.profiler.server.system;


/**
 * Provides methods for monitoring GC activities.
 *
 * @author  Misha Dmitriev
 */
public class GC {
    //~ Static fields/initializers -----------------------------------------------------------------------------------------------

    public static final int OBSERVED_PERIODS = 10; // must match OBSERVED_PERIODS in GC.c

    //~ Methods ------------------------------------------------------------------------------------------------------------------

    public static native int getCurrentGCEpoch();

    /**
     * Returns the following two numbers:
     * metrics[0] - (Sum GC pause time for the last 10 periods) / (Total execution time for the last 10 periods) * 1000
     * metrics[1] - last GC pause in microseconds
     */
    public static native void getGCRelativeTimeMetrics(long[] metrics);

    public static native void getGCStartFinishTimes(long[] start, long[] finish);

    public static native void activateGCEpochCounter(boolean activate);

    /** Should be called at earliest possible time */
    public static void initialize() {
        // Doesn't do anything in this version
    }

    /**
     * Returns true if two instances of class Object are adjacent in memory.
     * Used by our memory leak monitoring mechanism.
     * Doesn't work (always returns true) in vanilla JDK 1.5
     */
    public static native boolean objectsAdjacent(Object o1, Object o2);

    public static native void resetGCEpochCounter();

    public static native void runGC();
}
